package xddq

import (
	"fmt"
	"time"
	D "websocket_apn/define"
	"websocket_apn/log"
	"websocket_apn/proto"
)

//妖盟寻宝-处理解锁情况
func (xd *XdDriver) CheckUnionTreasureHuntInfoData(allInfo D.AllUnionTreasureHuntInfo) {
	msgCount := 0
	for _, info := range allInfo.Info {
		if info.Status == 0 {
			if info.Num > 0 {
				log.Infof("妖盟寻宝-开始解锁%s", info.Addr)
				xd.Send(proto.Get_Cmd_Data(xd.userInfo.PlayerId, proto.S_UNION_TREASURE_FILL_CHIP, fmt.Sprintf("08 %s", info.Addr)))
			} else {
				if msgCount < 2 {
					log.Infof("妖盟寻宝-开始索要%s", info.Addr)
					xd.Send(proto.Get_Cmd_Data(xd.userInfo.PlayerId, proto.S_UNION_TREASURE_ASK_FOR, fmt.Sprintf("08 %s", info.Addr)))
					msgCount++
				}
			}
		} else if info.Status == 2 {
			log.Infof("妖盟寻宝-开始挖宝%s", info.Addr)
			xd.Send(proto.Get_Cmd_Data(xd.userInfo.PlayerId, proto.S_UNION_TREASURE_HUNT_TREASURE, fmt.Sprintf("08 %s", info.Addr)))
		}
	}
}

//妖盟寻宝-处理画卷领取
func (xd *XdDriver) CheckUnionTreasureHuntDrawInfoData(allInfo []D.TreasureHuntDrawInfo) {
	for _, info := range allInfo {
		log.Infof("妖盟寻宝-领取%s赠送的画卷%s", info.Name, info.Addr)
		xd.Send(proto.Get_Cmd_Data(xd.userInfo.PlayerId, proto.S_UNION_TREASURE_GET_CHIP, fmt.Sprintf("0A %02X %s", len(info.GID)/2, info.GID)))
		time.Sleep(1 * time.Second)
	}
}
